<?php

// +----------------------------------------------------------------------
// | APP设备
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------

namespace app\model\app;

use app\model\file\Attachment;
use app\model\file\Image;
use app\model\ucenter\User;
use think\model\concern\SoftDelete;

class Video extends Common
{

    use SoftDelete;

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function cover()
    {
        return $this->belongsTo(Image::class,'cover_id');
    }

    public function video()
    {
        return $this->belongsTo(Attachment::class, 'video_id', 'id');
    }

    /**
     * 写入修改
     * @param $data
     */
    public static function onBeforeInsert($data)
    {
        $data['status'] = 1;
    }

    /**
     * 写入修改
     * @param $data
     */
    public static function onBeforeWrite($data)
    {
        $data['ip'] = request()->ip();
    }

}
